home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / clipper / nannws13.zip / ROUTINES.PRG < prev   
Text File  |  1987-02-24  |  6KB  |  176 lines

  1.  
  2. FUNCTION ROUNDER
  3. * Syntax:       ROUNDER(value,decimals)
  4. * Notes:    rounds value to specified number of decimal
  5. *               places. Workaround for ROUND() anomaly.
  6. PRIVATE in_num,places,rounded
  7. PARAMETERS in_num,places
  8. SET DECIMALS TO places
  9. rounded = (INT(in_num*10^places+.5))/10^places
  10. RETURN(rounded)
  11.  
  12.  
  13. FUNCTION CENTER
  14. * Syntax....:CENTER(<expC>,<expN>)
  15. * Notes.....:Returns the expC centered in the width expN by
  16. *           padding leading blanks.
  17. PRIVATE string, width
  18. PARAMETERS string, width
  19. IF LEN(string) >= width         && Too long to center
  20.    RETURN (string)
  21. ENDIF
  22. RETURN (SPACE(INT(width/2) -  INT(LEN(string)/2)) + string)
  23.  
  24.  
  25. FUNCTION GETSTR
  26. * Syntax....:GETSTR()
  27. * Notes.....:Returns and displays a string entered at the current
  28. *           cursor position.  Return terminates input. Unlike
  29. *           GET/READ does not clear previously pending GETs 
  30. PRIVATE char, string
  31. STORE "" TO char, string     && initialize to null
  32. DO WHILE .T.
  33.    char = INKEY(0)
  34.    DO CASE
  35.       CASE char = 13                    && Return terminates
  36.          EXIT
  37.       CASE char > 31 .AND. char < 127   && Printable character 
  38.          string = string + CHR(char)
  39.          @ ROW(),COL() SAY CHR(char)
  40.       CASE char = 8 .AND. LEN(string) > 0     && Backspace
  41.          @ ROW(),COL()-1 SAY " "
  42.          @ ROW(),COL()-1 SAY ""
  43.          string = SUBSTR(string,1,LEN(string)-1)
  44.    ENDCASE
  45. ENDDO
  46. RETURN (string)
  47.  
  48.  
  49. PROCEDURE MULTI_FORM
  50. *
  51. *  Author:   Ira Emus
  52. *  Date      December 1986
  53. *
  54. *  Notes:    Break your dBASE FMT file into separate files
  55. *              that correspond to the individual screen pages
  56. *              in the multi-page file.
  57. *            Remove the READ statements that demarcate pages. 
  58. *            Give the files a common name, enumerated, e.g.,
  59. *              T_SCR1.PRG, T_SCR2.PRG, ... ,T_SCR99.PRG.
  60. *            The filenames must have the extension PRG.
  61. *            Compile each file separately.
  62. *            Link the format files explicitly with your program,
  63. *              e.g., PLINK FI MYPROG,T_SCR1,T_SCR2,...
  64. *            Remove the SET FORMAT TO from your calling program
  65. *              and replace it with the following:
  66. *
  67. *              DO multi_form WITH <file name>,<number of pages>
  68. *
  69. *  Clipper does not support format files in the same fashion 
  70. *  that dBASE  does.  The main difference is that dBASE allows 
  71. *  multi page format files while Clipper only allows single 
  72. *  page format files.  Multi page format files may be simulated 
  73. *  in Clipper by the use of the following code.
  74. *
  75. PARAMETER scrn,maxpage              && pass name and number of files
  76. pg_count =  1                        && set format file to start with
  77.  
  78. DO WHILE .T.
  79.   form_no = ltrim(STR(pg_count))    && convert pg_count to form that
  80.   CLEAR    && works in macros. 
  81.   SET FORMAT TO &scrn&form_no        && Set format to current form
  82.   READ    && count and then read.
  83.   DO CASE
  84.     CASE LASTKEY() = 27              && if the last key hit was ESCAPE
  85.       EXIT    && then exit loop
  86.     CASE LASTKEY() = 18              && if the last key hit was PgUp then
  87.       IF pg_count > 1                && test for first page and exit,
  88.         pg_count=pg_count - 1        && otherwise decrememt page counter
  89.       ELSE
  90.         EXIT
  91.       ENDIF
  92.     OTHERWISE                        && any other exit key causes the page
  93.      IF pg_count < maxpage          && counter to be incremented until the
  94.         pg_count=pg_count + 1        && last page has been reached at which
  95.       ELSE                          && time the loop is exited
  96.         EXIT
  97.       ENDIF
  98.   ENDCASE
  99. ENDDO
  100. RETURN
  101.  
  102.  
  103.  
  104. FUNCTION MARGPRNT
  105. *
  106. * Author:  Steve Hillbourne
  107. * Date:    January, 1987
  108. *
  109. * Syntax:  MARGPRNT( HARDCR(<expC>) )
  110. *          where <expC> is the string to be wrapped,
  111. *          typically a memofield or output of 
  112. *          MEMOEDIT().
  113. *
  114. * Returns: nothing
  115. *
  116. * Notes:   preset margin as desired with SET MARGIN TO,
  117. *          this function then does the printing. 
  118. *
  119. PARAMETERS memo
  120. length = LEN(memo)
  121. position = 1
  122. offset = 1
  123. DO WHILE position < length
  124.    * search for carriage return
  125.    IF SUBSTR(memo,position,1) = CHR(13) 
  126.       * print line at a time
  127.       ? SUBSTR(memo, offset, position - offset)
  128.       * skip CR/LF and start new line
  129.       offset = position + 2
  130.       position = position + 1
  131.     ENDIF
  132.     position = position + 1
  133. ENDDO
  134. ?  SUBSTR(memo, offset)     && print last line
  135. RETURN ''
  136.  
  137.  
  138. FUNCTION MARGVAR
  139. *
  140. * Author:  Steve Hillbourne
  141. * Date:    January, 1987
  142. *
  143. * Syntax:  MARGVAR( HARDCR(<expC>) , <expN> )
  144. *          where <expN> is the desired indent  
  145. *          and <expC> is the string to be wrapped,
  146. *          typically a memofield or output of 
  147. *          MEMOEDIT().
  148. *
  149. * Returns: original text with built-in blanks for "indent",
  150. *          hard CRs (8Dh's), soft CRs (0Dh's), LFs (0Ah's)
  151. *          stripped out
  152. *
  153. * Notes:   SET MARGIN TO 0 before using
  154. *
  155. PARAMETERS memo,margin
  156. length = len(memo)
  157. position = 1
  158. offset = 1
  159. newmemo = ""
  160. DO WHILE position < length
  161.    * search for carriage return
  162.    IF SUBSTR(memo,position,1) = CHR(13)
  163.       * add margin within memofield
  164.       newmemo = newmemo + SPACE(margin) +;
  165.          SUBSTR(memo,offset,position+2-offset)
  166.       * skip CR/LF and move pointer
  167.       offset = position + 2
  168.       position = position + 1
  169.     ENDIF
  170.     position = position + 1
  171. ENDDO
  172. * add last line
  173. newmemo = newmemo + SPACE(margin) + SUBSTR(memo,offset)
  174. RETURN newmemo
  175.  
  176.